/** 右上角标题对象.. IVMU 里面通用对象 **/
package anshe.object
{
	import anshe.event.TitleEvent;
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.dstart.object.memo.MemoObject;

	public class TitleObject extends Sprite
	{
		public var bgTitle:Sprite;			//	底部框
		public var btnHelp:SimpleButton;	//	帮助按钮
		public var btnMin:SimpleButton;		//	最小化按钮
		public var btnReturn:SimpleButton;	//	还原按钮
		public var btnMove:SimpleButton;	//	移动按钮
		public var btnClose:SimpleButton;	//	关闭按钮
		
		public function TitleObject()
		{
			InitObject();
			InitMemo();
			InitListener();
		}
		
		private function InitObject():void
		{
			// this.cacheAsBitmap = true;

			btnReturn.visible = false;
		}
		
		private function InitMemo():void
		{
			MemoObject.ShowPlace = 15;
			
			MemoObject.create(btnClose, "Close");
			MemoObject.create(btnMin, "Minimize");
			MemoObject.create(btnReturn, "Restore");
			MemoObject.create(btnHelp, "Help");
			MemoObject.create(btnMove, "Move");
		}
		
		private function InitListener():void
		{
			btnMin.addEventListener(MouseEvent.CLICK, onBtnMinClick);
			btnReturn.addEventListener(MouseEvent.CLICK, onBtnReturnClick);
			btnClose.addEventListener(MouseEvent.CLICK, onBtnCloseClick);
			btnHelp.addEventListener(MouseEvent.CLICK, onBtnHelpClick);
			
			btnMove.addEventListener(MouseEvent.MOUSE_DOWN, onStartDragWindow);
			btnMove.addEventListener(MouseEvent.MOUSE_UP, onStopDragWindow);
		}	
		
		// 开始 拖动窗口
		private function onStartDragWindow(e:MouseEvent):void
		{
			dispatchEvent(new Event(TitleEvent.START_DRAG));			
		}

		// 停止 拖动窗口
		private function onStopDragWindow(e:MouseEvent):void
		{
			dispatchEvent(new Event(TitleEvent.STOP_DRAG));			
		}
	
		// 点击 最小化 按钮
		private function onBtnMinClick(e:MouseEvent):void
		{
			btnMin.visible = false;
			btnReturn.visible = true;
			
			dispatchEvent(new Event(TitleEvent.MIN_WINDOW));
		}
		
		// 点击 还原 按钮
		private function onBtnReturnClick(e:MouseEvent):void
		{
			btnMin.visible = true;
			btnReturn.visible = false;
			
			dispatchEvent(new Event(TitleEvent.RETURN_WINDOW));
		}	
		
		// 点击 关闭窗口 按钮
		private function onBtnCloseClick(e:MouseEvent):void
		{
			dispatchEvent(new Event(TitleEvent.CLOSE_WINDOW));			
		}
		
		// 点击 帮助 按钮 
		private function onBtnHelpClick(e:MouseEvent):void
		{
			dispatchEvent(new Event(TitleEvent.SHOW_HELP));			
		}
	}
}